package com.gadgets.cm01.auth.dto;

import com.gadgets.cm01.auth.pojo.Authority;
import com.gadgets.framework.common.dto.BaseDTO;

import java.util.ArrayList;
import java.util.List;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-09-29
 *
 */
public class AuthorityTreeDTO extends BaseDTO {

    public AuthorityTreeDTO() {
    }

    public AuthorityTreeDTO(List<Authority> sonAuthList) {
        this.sonAuthList = new ArrayList<>(sonAuthList.size()-1);
        for (int i = 0; i < sonAuthList.size(); i++) {
            Authority auth = sonAuthList.get(i);
            if(0==i){
                // 构建首节点
                this.authorityName = auth.getAuthName();
                this.authPath = auth.getAuthPath();
                this.authType = auth.getAuthType();
                this.authId = auth.getId();
            }else {
                // 构建子节点
                AuthorityTreeDTO sonNode = new AuthorityTreeDTO();
                sonNode.setAuthorityName(auth.getAuthName());
                sonNode.setAuthPath(auth.getAuthPath());
                sonNode.setAuthType(auth.getAuthType());
                sonNode.setAuthId(auth.getId());
                this.sonAuthList.add(sonNode);
            }
        }
    }

    /**
     * 菜单名
     */
    private String authorityName;
    /**
     * 菜单类型
     */
    private Integer authType;
    /**
     * 菜单路径
     */
    private String authPath;
    /**
     * 菜單ID
     */
    private Long authId;
    /**
     * 子菜单列表
     */
    private List<AuthorityTreeDTO> sonAuthList;

    public String getAuthorityName() {
        return authorityName;
    }

    public void setAuthorityName(String authorityName) {
        this.authorityName = authorityName;
    }

    public Integer getAuthType() {
        return authType;
    }

    public void setAuthType(Integer authType) {
        this.authType = authType;
    }

    public String getAuthPath() {
        return authPath;
    }

    public void setAuthPath(String authPath) {
        this.authPath = authPath;
    }

    public List<AuthorityTreeDTO> getSonAuthList() {
        return sonAuthList;
    }

    public void setSonAuthList(List<AuthorityTreeDTO> sonAuthList) {
        this.sonAuthList = sonAuthList;
    }

    public Long getAuthId() {
        return authId;
    }

    public void setAuthId(Long authId) {
        this.authId = authId;
    }

}
